<?php
/**
 * Created by PhpStorm.
 * User: woody
 * Date: 17-2-16
 * Time: 下午10:46
 */

namespace App\Http\Controllers\Admin;

use App\Blocks\Activity;
use App\Models\Dashboard;
use App\Models\EatEveryDayPrize;

use Illuminate\Http\Request;
use Validator , Config , Session , Cookie;

class EatEveryDayPrizeController extends AdminController {


    public function index(Request $request){
        $page = $request->get('page', 1);
        $pageSize = $request->get('pageSize', 20);
        $search = [];
        if($request->has('search')){
            $search['search'] = $request->get('search');
        }
        $activityBlock = new Activity();
        $data=$activityBlock->eatEveryDayPrizeList($search, $page, $pageSize);
        $eatEveryDayPrize = new Dashboard();
        $total=$eatEveryDayPrize->CountPrize();
        return response()->json(['code' => 0, 'msg' => '', 'data' => $data , 'total' => $total]);
    }

    public function cashPrize(Request $request){
        $id = $request->get('id');
        $redeemCode = $request->get('redeem_code');

        if(
        EatEveryDayPrize::where('id', $id)->where('redeem_code', $redeemCode)
            ->where('status', 0)
            ->whereNull('deleted_at')
            ->update(['status' => 1])
        ){
            return response()->json(['code' => 0, 'msg' => '']);
        }else{
            return response()->json(['code' => -1, 'msg' => '兑奖失败']);
        }
    }



}